import os,shutil
import random
import xml.etree.ElementTree as ET

from utils.utils import get_classes

def copyfile(src,dst):
    if not os.path.isfile(src):
        print("%s not exist",src)
    else:
        shutil.copyfile(src,dst)

path = 'J:\python\yolov4-tiny-keras-master'
if __name__ == "__main__":
    trainImgPath = os.path.join(path, 'VOCdevkit\VOC2007\JPEGImages')
    imgPath = os.path.join(path, 'img')
    testFile = os.path.join(path,"VOCdevkit\VOC2007\ImageSets\Main\\test.txt")
    
    #读取测试样本文件
    f = open(testFile,"r",encoding='UTF-8')
    lines = f.readlines()
    f.close()
    for line in lines:
        fileName = line.replace('\n','')
        # fileName = os.path.split(fileName)+'.jpg'
        srcFile = os.path.join(trainImgPath,fileName+".jpg")
        dstFile = os.path.join(imgPath,fileName+".jpg")
        #拷贝文件
        copyfile(srcFile,dstFile)
